<?php

namespace app\common\model;

use think\Model;
use think\Db;
use think\Config;
use think\Loader;

class EventUser extends Model {

    // 指定表名,不含前缀
    protected $name = 'event_user';


    public function getListByIds($ids = null) {
        if ($ids == null) {
            $ids = 0;
        }
        $questype = Db::name($this->name)->field('identity_id,username,usertruename')->where(['eventid' => $ids])->select();
        return $questype;
    }
	
	
	public function Suthority($identity_id,$type=0) {
        if ($identity_id == null) {
            $identity_id = 0;
        }
		$data = array();
		
		$cont = ['identity_id ' => $identity_id];
		if($type){
			$cont['feedback']=1;
		}
        $questype = Db::name($this->name)->field('eventid')->where($cont)->select();
		foreach($questype as $v){
			$data[] = $v['eventid'];
		}
        return $data;
    }

	public function userinfor($reg,$Ucid=0) {
        
		$data = array();
		$projectevent = Db::name('project_event')->field('id')->where(['admin_id'=>$Ucid,'isdelete'=>0])->select();
		$id=[0];
		foreach($projectevent as $v){
			$id[] = $v['id'];
		}
		
        $questype = Db::name($this->name)->field('distinct identity_id,usertruename username')->where(['status'=>1,'isdelete'=>0,'eventid'=>['in',$id]])->select();
		foreach($questype as $v){
			$data[$v['identity_id']] = $v['username'];
		}
        return $data;
    }

	/**
	 * [getUserCount description]
	 * @param  [int] $id [工程ID]
	 * @return [int]     [返回该工程下有多少人]
	 */
    public function getUserCount($id){

    	$condition = array();
    	if(!empty($id))  $condition = ['eventid'=>$id];
    	$result =  Db::name($this->name)->field('count(*) as total')->where($condition)->find();
    	return $result['total'];
    }
	
	public function getListByArgOne($arg, $field = '*')
    {
        
            return $this->where($arg)->field($field)->find();
        
    }
	
	public function getListInfoByArg($arg,$field = '*',$left_join = null){
        if (empty($left_join)){
            $arg = $this->where($arg)->field($field)->select();
        }else{
            $table = $left_join[0];
            $condition = $left_join[1];
            $arg = $this->alias('a')->where($arg)->join($table,$condition,'left')->field($field)->select();
        }

        return $arg;
    }
	
}
